package com.huawei.hms.framework.network.grs.c;

import android.text.TextUtils;
import com.huawei.hms.aaid.constant.AaidIdConstant;
import com.huawei.hms.framework.common.Logger;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Pattern;

public class c {
    private static final String a = c.class.getSimpleName();
    private static final Pattern b = Pattern.compile("[0-9]*[a-z|A-Z]*[一-龥]*");

    public static String a(String str) {
        return a(str, AaidIdConstant.SIGNATURE_SHA256);
    }

    private static String a(String str, String str2) {
        String str3 = null;
        try {
            try {
                str3 = a(MessageDigest.getInstance(str2).digest(str.getBytes("UTF-8")));
            } catch (NoSuchAlgorithmException e) {
                Logger.w(a, "encrypt NoSuchAlgorithmException");
            }
        } catch (UnsupportedEncodingException e2) {
            Logger.w(a, "encrypt UnsupportedEncodingException");
        }
        return str3;
    }

    private static String a(byte[] bArr) {
        StringBuffer stringBuffer = new StringBuffer();
        for (byte b : bArr) {
            String toHexString = Integer.toHexString(b & 255);
            if (toHexString.length() == 1) {
                stringBuffer.append("0");
            }
            stringBuffer.append(toHexString);
        }
        return stringBuffer.toString();
    }

    public static String b(String str) {
        int i = 1;
        if (TextUtils.isEmpty(str)) {
            return str;
        }
        String str2 = "*";
        if (str.length() == 1) {
            return "*";
        }
        StringBuffer stringBuffer = new StringBuffer();
        for (int i2 = 0; i2 < str.length(); i2++) {
            String str3 = str.charAt(i2) + "";
            if (b.matcher(str3).matches()) {
                if (i % 2 == 0) {
                    str3 = "*";
                }
                i++;
            }
            stringBuffer.append(str3);
        }
        return stringBuffer.toString();
    }
}
